// Copyright (c) Appeon. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. 
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.

using System;
using System.Collections.Generic;

namespace SnapObjects.Data
{
    internal class SqlFunctionStatement : SqlStatement
    {
        public SqlFunctionStatement(FunctionReturnType returnType)
        {
            this.Function = new SqlClause();
            this.Parameters = new Dictionary<string, SqlParameterToken>(StringComparer.OrdinalIgnoreCase);
            this.ReturnType = returnType;
        }

        public override SqlStatementType StatementType => SqlStatementType.Function;

        public override SqlTokenType Type => SqlTokenType.Statement;

        public FunctionReturnType ReturnType { get; }

        public SqlClause Function { get; private set; }

        public IDictionary<string, SqlParameterToken> Parameters { get; private set; }

        public override void Clear()
        {
            this.Function.Clear();
            this.Parameters.Clear();
        }

        public override SqlStatement Clone()
        {
            return new SqlFunctionStatement(this.ReturnType)
            {
                Function = this.Function.Clone(),
                Parameters = new Dictionary<string, SqlParameterToken>(
                    this.Parameters, StringComparer.OrdinalIgnoreCase)
            };
        }
    }
}
